package com.glodon.paas.account.security.openid.association;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openid4java.association.Association;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

/**
 * @author Don Li
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-config-test.xml")
public class RedisServerAssociationStoreIT {

    @Autowired
    private RedisServerAssociationStore store;

    @Test
    public void testGenerate() throws Exception {
        Association original = store.generate(Association.TYPE_HMAC_SHA1, 120);
        Association loaded = store.load(original.getHandle());
        assertNotNull(loaded);
        assertThat(loaded.getType(), is(Association.TYPE_HMAC_SHA1));
    }

    @Test
    public void testRemove() throws Exception {
        Association original = store.generate(Association.TYPE_HMAC_SHA256, 120);
        store.remove(original.getHandle());
        assertNull(store.load(original.getHandle()));
    }
}
